package com.example.springboot.jdbc.usermanager.service;

import com.example.springboot.jdbc.usermanager.dao.UserDao;
import com.example.springboot.jdbc.usermanager.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.ResultSet;
import java.sql.SQLException;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Transactional
	@Override
	public int insert(User user) {
//		测试事物是否起作用，如果没有保存成功，则事物生效
//		int a = 1/0;
		return userDao.insert(user);
	}

	@Transactional
	@Override
	public int deleteById(Integer id) {
		return userDao.deleteById(id);
	}

	@Transactional
	@Override
	public int update(User user) {
		return userDao.update(user);
	}

	@Override
	public User getById(Integer id) {
		return userDao.getById(id);
	}

}